function dist = getDistToRoot(tree, nodeName)
%UNTITLED Summary of this function goes here
%   Detailed explanation goes here

node = getbyname(tree, nodeName);
nodeNum = -1;
rootNode = getbyname(tree, 'root');
rootNum = -1;

for i = 1:size(node, 1)
    if (node(i, 1) == 1)
        nodeNum = i;
    end
    if (rootNode(i, 1) == 1)
        rootNum = i;
    end
end

[mat, id, dists] = getmatrix(tree);
dist = 0;
curNodeNum = nodeNum;
while (curNodeNum ~= rootNum)
    distIdx = 0;
    %fprintf('curnode is %d\n', curNodeNum);
    for i = 1:size(mat, 2)
        for j = 1:size(mat, 1)
            if (mat(j, i) == 1)
                distIdx = distIdx + 1;
                %fprintf('connection between %d and %d\n', i, j);
                
                if (i == curNodeNum)
                    curNodeNum = j;
                    dist = dist + dists(distIdx);
                    %fprintf('dist from %d to %d is %d\n', i, j, dists(distIdx));
                end
            end

        end
    end
end

end

